home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / Debugger Strip ƒ / debug.c next >
Encoding:
C/C++ Source or Header  |  1994-10-01  |  2.9 KB  |  115 lines  |  [TEXT/MMCC]

  1. /**************
  2. Debug Strip GH, a simple demonstration of how to write a 
  3. control strip module. 8/18/94
  4.  
  5. This module simply drops into MacsBug when clicked.
  6.  
  7. Read the Software section of the Developer Notes on the Powerbook 500 series.
  8.  
  9. I am unable to include the file "controlstrip.h", but it should be available
  10. in a variety of places.it is in the current Universal Header distribution (ETO 15) 
  11. and should be available from Think or MetroWerks. (It isn't in MetroWerks CW4). 
  12. You might check ftp.apple.com to see if there is an up-to-date Universal Header
  13. distribution there.
  14.  
  15. There is an unofficial version that comes with the Control Strip Patcher
  16. *****************/
  17.  
  18. #include "debug.h"
  19. #include <Icons.h>
  20. #include "controlstrip.h"
  21. pascal long main (long message, long params, Rect *statusRect, GrafPtr statusPort)
  22. {
  23.     long result = 0L;
  24.     
  25.     switch (message)
  26.     {
  27.         case sdevInitModule: // check environs, allocate globals
  28.             result = DoCSInit();
  29.         break;
  30.         case sdevCloseModule: // release my memory
  31.             DoCSClose((MyGlobalHandle) params);
  32.         break;
  33.         case sdevFeatures: // let the strip track the mouse down
  34.             result = (1L << sdevWantMouseClicks);
  35.         break;
  36.         case sdevGetDisplayWidth:
  37.             result = 16L; // size of a small icon width
  38.         break;
  39.         case sdevPeriodicTickle:
  40.         break;
  41.         case sdevDrawStatus: // draw my icon
  42.             DoCSDraw((MyGlobalHandle) params, statusRect, statusPort);
  43.         break;
  44.         case sdevMouseClick: // the mouse was clicked & released in my button
  45.             DoCDClick((MyGlobalHandle) params);
  46.         break;
  47.         case sdevSaveSettings:
  48.         break;
  49.         case sdevShowBalloonHelp:
  50.         break;
  51.         
  52.     }
  53.     return (result);
  54. }
  55. void DoCDClick(MyGlobalHandle myGlobals)
  56. {
  57.     Debugger();
  58. }
  59.  
  60. long DoCSInit(void)
  61. {
  62.     MyGlobalHandle    myH;
  63.     OSErr            iErr;
  64.     Handle            iconSuite = 0L;
  65.     if (HasDebugger()) // is a debugger installed?
  66.     {
  67.         myH = (MyGlobalHandle) NewHandleClear(sizeof(MyGlobals));
  68.         if (myH) // was I able to allocate my memory?
  69.         {
  70.             iErr = SBGetDetachIconSuite(&iconSuite, 669, 0x0000FF00L);
  71.             (*myH)->iconSuite = iconSuite;
  72.             return ((long) myH);
  73.         }
  74.     }
  75.     return (-1L); // something went wrong, don't install
  76. }
  77. void DoCSClose(MyGlobalHandle myGlobals)
  78. {
  79.     if (myGlobals) 
  80.     {
  81.         if ((*myGlobals)->iconSuite)
  82.         {
  83.             DisposeIconSuite ((*myGlobals)->iconSuite, true);
  84.         }
  85.         DisposeHandle((Handle) myGlobals);
  86.     }
  87. }
  88. void DoCSDraw(MyGlobalHandle myGlobals, Rect *statusRect, GrafPtr statusPort)
  89. {
  90.     OSErr        iErr;
  91.     Rect        theRect;
  92.     short        alignment = 0x01 + 0x04; // center up & down , and left & right
  93.     long        transform = 0; // no transform
  94.     
  95.     if ((*myGlobals)->iconSuite)
  96.     {
  97.         theRect.top = statusRect->top;
  98.         theRect.left = statusRect->left;
  99.         theRect.bottom = statusRect->bottom;
  100.         theRect.right = statusRect->right;
  101.         iErr = PlotIconSuite(&theRect,alignment,transform,(*myGlobals)->iconSuite);
  102.     }
  103. }
  104. Boolean HasDebugger(void)
  105. {
  106.     OSErr            err;
  107.     long            *jmpAddress;
  108.     
  109.     jmpAddress = (long *) 0x120L; // address of entry routine for a debugger
  110.     
  111.     if (*jmpAddress) 
  112.         return (true);
  113.     else
  114.         return (false);
  115. }